﻿<template>
	<transition name="el-zoom-in-center">
		<div class="JNPF-preview-main">
			<div class="JNPF-common-page-header">
				<el-page-header @back="goBack" :content="!dataForm.id ? '新建' : isDetail ? '详情' : '编辑'"/>
				<div class="options">
					<el-button type="primary" @click="dataFormSubmit()" v-if="!isDetail">确 定</el-button>
					<el-button @click="goBack">取 消</el-button>
				</div>
			</div>
			<el-row :gutter="15"  class="main" :style="{margin: '0 auto',width:'100%'}">
				<el-form ref="elForm" :model="dataForm" size="medium" label-width="100px" label-position="right" :disabled="!!isDetail" :rules="rules">
					<el-col :span="24" >
						<el-form-item label="仓库名称" prop="name">
							<el-input v-model="dataForm.name" placeholder="请输入" clearable required :style='{"width":"100%"}' >
							</el-input>
						</el-form-item>
					</el-col>
					<el-col :span="24" >
						<el-form-item label="联系人" prop="desPerson">
							<user-select v-model="dataForm.desPerson" placeholder="请选择" required >
							</user-select>
						</el-form-item>
					</el-col>
					<el-col :span="24" >
						<el-form-item label="联系电话" prop="desPersonPhone">
							<el-input v-model="dataForm.desPersonPhone" placeholder="请输入" clearable required :style='{"width":"100%"}' >
							</el-input>
						</el-form-item>
					</el-col>
					<el-col :span="24" >
						<el-form-item label="仓管员" prop="admin">
							<user-select v-model="dataForm.admin" placeholder="请选择" required >
							</user-select>
						</el-form-item>
					</el-col>
					<el-col :span="24" >
						<el-form-item label="所在地区" prop="area">
							<JNPF-Address v-model="dataForm.area" placeholder="请选择" required :level="2" >
							</JNPF-Address>
						</el-form-item>
					</el-col>
					<el-col :span="24" >
						<el-form-item label="详细地址" prop="address">
							<el-input v-model="dataForm.address" placeholder="请输入" clearable :style='{"width":"100%"}' >
							</el-input>
						</el-form-item>
					</el-col>
					<el-col :span="24" >
						<el-form-item label="备注" prop="remark">
							<el-input v-model="dataForm.remark" placeholder="请输入" show-word-limit :style='{"width":"100%"}'  type="textarea" :autosize='{"minRows":4,"maxRows":4}' >
							</el-input>
						</el-form-item>
					</el-col>
					<el-col :span="24" >
						<el-form-item label="图片" prop="photos">
							<JNPF-UploadImg v-model="dataForm.photos" :fileSize="2" sizeUnit="MB" :limit="9" >
							</JNPF-UploadImg>
						</el-form-item>
					</el-col>
					<el-col :span="6" v-if="false" >
						<el-form-item label="创建用户" prop="creatorUserId">
							<el-input v-model="dataForm.creatorUserId" placeholder="系统自动生成" readonly >
							</el-input>
						</el-form-item>
					</el-col>
					<el-col :span="6" v-if="false" >
						<el-form-item label="创建时间" prop="creatorTime">
							<el-input v-model="dataForm.creatorTime" placeholder="系统自动生成" readonly >
							</el-input>
						</el-form-item>
					</el-col>
					<el-col :span="6" v-if="false" >
						<el-form-item label="修改人员" prop="lastModifyer">
							<el-input v-model="dataForm.lastModifyer" placeholder="系统自动生成" readonly >
							</el-input>
						</el-form-item>
					</el-col>
					<el-col :span="6" v-if="false" >
						<el-form-item label="修改时间" prop="lastModifyTime">
							<el-input v-model="dataForm.lastModifyTime" placeholder="系统自动生成" readonly >
							</el-input>
						</el-form-item>
					</el-col>
				</el-form>
			</el-row>
		</div>
	</transition>
</template>
<script>
	import request from '@/utils/request'
	import { getDictionaryDataSelector } from '@/api/systemData/dictionary'
	import { previewDataInterface } from '@/api/systemData/dataInterface'
	export default {
		components: {},
		props: [],
		data() {
			return {
				loading: false,
				visible: false,
				isDetail: false,
				dataForm: {
					name:undefined,
					desPerson:undefined,
					desPersonPhone:undefined,
					admin:undefined,
					area:[],
					address:undefined,
					remark:undefined,
					photos:[],
					creatorUserId:undefined,
					creatorTime:undefined,
					lastModifyer:undefined,
					lastModifyTime:undefined,
				},
				rules: {
					name:[
						{
							required:true,
							message:'请输入仓库名称',
							trigger:'blur'
						},
					],
					desPerson:[
						{
							required:true,
							message:'请输入联系人',
							trigger:'change'
						},
					],
					desPersonPhone:[
						{
							required:true,
							message:'请输入联系电话',
							trigger:'blur'
						},
						{
							pattern:/^1[3456789]\d{9}$|^0\d{2,3}-?\d{7,8}$/,
							message:'请输入正确的联系方式',
							trigger:'blur'
						},
					],
					admin:[
						{
							required:true,
							message:'请输入仓管员',
							trigger:'change'
						},
					],
					area:[
						{
							required:true,
							message:'请输入所在地区',
							trigger:'change'
						},
					],
				},
			}
		},
		computed: {},
        watch: {},
        created() {
		},
		mounted() {
        },
		methods: {
			goBack() {
                this.$emit('refresh')
            },
			init(id, isDetail) {
				this.dataForm.id = id || 0;
                this.visible = true;
                this.isDetail = isDetail || false;
				this.$nextTick(() => {
					this.$refs['elForm'].resetFields();
					if (this.dataForm.id) {
						request({
							url: '/api/SubDev/ZyOaGoods/' + this.dataForm.id,
							method: 'get'
						}).then(res =>{
							this.dataForm = res.data;
						})
					}
				})
			},
			dataFormSubmit() {
				this.$refs['elForm'].validate((valid) => {
                    if (valid) {
                        if (!this.dataForm.id) {
                            request({
                                url: `/api/SubDev/ZyOaGoods`,
                                method: 'post',
                                data: this.dataForm,
                            }).then((res) => {
                                this.$message({
                                    message: res.msg,
                                    type: 'success',
                                    duration: 1000,
                                    onClose: () => {
                                        this.visible = false,
                                            this.$emit('refresh', true)
                                    }
                                })
                            })
                        } else {
                            request({
                                url: '/api/SubDev/ZyOaGoods/' + this.dataForm.id,
                                method: 'PUT',
                                data: this.dataForm
                            }).then((res) => {
                                this.$message({
                                    message: res.msg,
                                    type: 'success',
                                    duration: 1000,
                                    onClose: () => {
                                        this.visible = false
                                        this.$emit('refresh', true)
                                    }
                                })
                            })
                        }
                    }
                })
			},
		}
	}
</script>
